let types = require('../constants');
let tokenTypes = require('./token-types');
let astModule = require('../modules/ast-module');
let astNodeTags = require('./ast-node-tags');

let nodeUtil = {
  _getLiteralTag(token) {
    switch (token.type) {
      case tokenTypes.WORD:
        return astNodeTags.WORD;
      case tokenTypes.DIGIT:
        return astNodeTags.DIGIT;
      case tokenTypes.EXPRESSION:
        return astNodeTags.EXP;
      case tokenTypes.URI:
        return astNodeTags.URI;
    }
  },
  genLiteralNode(token) {
    let tag = this._getLiteralTag(token);
    return new astModule.Literal(tag, token);
  },
  isNodeLiteral(node) {
    return node instanceof astModule.Literal;
  },
  getLiteralValue(node) {
    return node.value.value;
  },
  getShowCommandScope(node) {
    if (node.operator.type == tokenTypes.DOLLOR) {
      return types.PROPERTY_SCOPE.OTHER;
    } else {
      return types.PROPERTY_SCOPE.ARGS;
    }
  },
  getExpTag(operator) {
    switch (operator.type) {
      case tokenTypes.ASSIGN:
        return astNodeTags.ASSIGN;
      case tokenTypes.POINT:
        return astNodeTags.POINT;
      case tokenTypes.POS:
        return astNodeTags.POS;
      case tokenTypes.DOT:
        return astNodeTags.DOT;
      case tokenTypes.DOLLOR:
        return astNodeTags.DOLLOR;
    }
  }
};

module.exports = nodeUtil;
